package com.motus.pm.daoImpl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.motus.pm.dao.ProjectInfoDao;
import com.motus.pm.vo.PmProjectInfo;

@Repository
public class ProjectInfoDaoImpl extends BaseDaoImpl<PmProjectInfo> implements ProjectInfoDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<PmProjectInfo> getProjectInfosByDeptId(int deptId) {
		Session session=sessionFactory.getCurrentSession();
		String sql="select * from pm_project_info where pid in"+
				   "(select distinct pid from pm_project_phase where phase_id in"+
				   "(select phase_id from pm_phase_info where depart_id = ?))";
		Query query=session.createSQLQuery(sql).addEntity(PmProjectInfo.class);
		query.setInteger(0, deptId);
		return query.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PmProjectInfo> getProjectInfosByState(int proState) {

		Session session=sessionFactory.getCurrentSession();
		String hql="from PmProjectInfo where proState=?";
		Query query=session.createQuery(hql);
		query.setInteger(0, proState);
		return query.list();
	}

}
